<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增流程节点逻辑配置')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-steplogic-add">
        <input type="hidden" name="versionId" id="versionId" th:value="${versionId}"/>
        <input type="hidden" name="stepId" id="stepId" th:value="${stepId}"/>
        <input type="hidden" name="deptId" id="deptId" th:value="${deptId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label  is-required">逻辑类型：</label>
            <div class="col-sm-8">
                <select name="logicType" id="logicType" class="form-control m-b"
                        th:with="type=${@dict.getType('wfl_logic_type')}" onchange="logicTypeChange()"
                        required>
                    <option value="">请选择</option>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">风险策略：</label>
            <div class="col-sm-8">
                <select name="riskStrategy" id="riskStrategy" class="form-control m-b"
                        th:with="type=${@strategyGroup.selectStrategyGroupList(deptId)}">
                    <option value="">请选择</option>
                    <option th:each="strategy : ${type}" th:text="${strategy.groupName}"
                            th:value="${strategy.groupId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">外部类名称：</label>
            <div class="col-sm-8">
                <input name="className" id="className" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">外部类方法名：</label>
            <div class="col-sm-8">
                <input name="methodName" id="methodName" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">方法参数说明：</label>
            <div class="col-sm-8">
                <p class="form-control-static">
                    Map={"instanceId":"2021120814050400000011","cname":"张三","cardNum":"511423199111150019","phoneNum":"18611111144"}</p>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label  is-required">执行时点：</label>
            <div class="col-sm-8">
                <select name="runSts" class="form-control m-b" th:with="type=${@dict.getType('wfl_run_sts')}" required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea name="description" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "workflow/steplogic"
    $("#form-steplogic-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            //逻辑类型
            var logicType = $("#logicType").val();
            var riskStrategy = $("#riskStrategy").val();
            if (logicType == 1 && riskStrategy == "") {
                $.modal.alertWarning("请选择风险策略！");
                return false;
            }
            var className = $("#className").val();
            if (logicType == 2 && className == "") {
                $.modal.alertWarning("请填写外部类名称！");
                return false;
            }
            var methodName = $("#methodName").val();
            if (logicType == 2 && methodName == "") {
                $.modal.alertWarning("请填写外部类方法名！");
                return false;
            }
            var paramName = $("#paramName").val();
            if (logicType == 2 && paramName == "") {
                $.modal.alertWarning("请填写方法参数！");
                return false;
            }
            //$.operate.save(prefix + "/add", $('#form-steplogic-add').serialize());
            var code = -1;
            $.ajax({
                url: prefix + "/add",
                data: $('#form-steplogic-add').serialize(),
                async: false,
                type: "post",
                success: function (result) {
                    code = result.code;
                }
            });
            if (code == 0) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    function logicTypeChange() {
        //逻辑类型
        var logicType = $("#logicType").val();
        if (logicType == 2) {
            $("#riskStrategy").attr("disabled", "disabled");
            $("#riskStrategy").val("");
            $("#className").removeAttr("disabled");
            $("#methodName").removeAttr("disabled");
        } else {
            $("#riskStrategy").removeAttr("disabled");
            $("#className").attr("disabled", "disabled");
            $("#methodName").attr("disabled", "disabled");
            $("#className").val("");
            $("#methodName").val("");
        }
    }

</script>
</body>
</html>